/*
 * @Descripttion: jsjiami.com.v6.js
 * @Version: 1.0
 * @Author: undead
 * @Date: 2022-01-12 16:31:59
 * @LastEditors: undead
 * @LastEditTime: 2022-02-08 14:35:01
 */
const traverse = require("@babel/traverse").default;
const generator = require("@babel/generator").default;
const astUtils = require("./ast-utils");

module.exports = {
  name: "jsjiami.com.v6",
  checkFeature: function (nodes) {
    const lastNode = nodes.program.body.at(-1);
    return (
      lastNode.type === "ExpressionStatement" &&
      lastNode.expression.right !== undefined &&
      lastNode.expression.right.value === "jsjiami.com.v6"
    );
  },
  init: function (nodes) {
    //防止移除后，编译器报错
    traverse(nodes, {
      StringLiteral: (path) => {
        astUtils.removeLine(path, " ");
      },
    });
    traverse(nodes, { VariableDeclarator: { exit: [astUtils.mergeObject] } });
    traverse(nodes, { VariableDeclarator: { exit: [astUtils.callToString] } });
    traverse(nodes, { ExpressionStatement: astUtils.convParam });
    traverse(nodes, { WhileStatement: { exit: [astUtils.replaceWhile] } });
    traverse(nodes, { ExpressionStatement: astUtils.removeComma });
    traverse(nodes, { VariableDeclaration: astUtils.removeVarComma });
    traverse(nodes, { VariableDeclarator: astUtils.conditionVarToIf });
    traverse(nodes, { ExpressionStatement: astUtils.ConditionToIf });
    return nodes;
  },
};
